using System;
using System.Collections;
using UnityEngine;

public class InfoDisplay : MonoBehaviour
{
	private static InfoDisplay instance;
 
	public static InfoDisplay Instance
	{
		get
		{
			if (instance == null)
			{
				instance = new GameObject("InfoDisplay").AddComponent<InfoDisplay>();
				InfoDisplay.initialize();
			}
 
			return instance;
		}
	}
	
	public static GameObject infoBox;
	public static GameObject sprite;
	public static UILabel infoLabel;
 
	
	public void displayMessage(string m, float t = Mathf.Infinity, string hexaColor = "000000"){
		
		
		TweenScale tween = TweenScale.Begin(sprite,1f,new Vector3(sprite.transform.localScale.x,50,sprite.transform.localScale.z));
		tween.method = UITweener.Method.EaseOut;
		
		TweenAlpha tween2 = TweenAlpha.Begin(infoLabel.gameObject,1.8f,1);
		tween2.method = UITweener.Method.EaseIn;
		
		infoLabel.text = "["+hexaColor+"]"+m;
		StopAllCoroutines();
		StartCoroutine(hideMessage(t));
		
	}
	
	public void hideMessageNow(){
		StopAllCoroutines();
		sprite.transform.localScale = new Vector3(sprite.transform.localScale.x,0.1f,sprite.transform.localScale.z);
		infoLabel.alpha = 0;
	}
	
	public IEnumerator hideMessage(float t){
		yield return new WaitForSeconds(t);
		TweenScale.Begin(sprite,1f,new Vector3(sprite.transform.localScale.x,0.1f,sprite.transform.localScale.z));
		TweenAlpha.Begin(infoLabel.gameObject,0.3f,0);
	}
	
	public static void initialize(){
		infoBox = GameObject.Find("InfoBox");
		sprite = GameObject.Find("InfoSprite");
		infoLabel = GameObject.Find("InfoLabel").GetComponent<UILabel>();
		
	}
	
}

